package org.jeecg.modules.system.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysDepartPosition;
import org.jeecg.modules.system.entity.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @Author scott
 * @since 2018-12-20
 */
public interface SysUserMapper extends BaseMapper<SysUser> {
	/**
	  * 通过用户账号查询用户信息
	 * @param username
	 * @return
	 */
	@SqlParser(filter = true)
	public SysUser getUserByName(@Param("username") String username);

	/**
	 *  根据部门Id查询用户信息
	 * @param page
	 * @param departId
	 * @return
	 */
	IPage<SysUser> getUserByDepId(Page page, @Param("departId") String departId, @Param("username") String username);

	/**
	 * 根据角色Id查询用户信息
	 * @param page
	 * @param
	 * @return
	 */
	IPage<SysUser> getUserByRoleId(Page page, @Param("roleId") String roleId, @Param("username") String username);
	
	/**
	 * 根据用户名设置部门ID
	 * @param username
	 * @param orgCode
	 */
	void updateUserDepart(@Param("username") String username, @Param("orgCode") String orgCode);


	/**
	 * 根据手机号查询用户信息
	 * @param phone
	 * @return
	 */
	public SysUser getUserByPhone(@Param("phone") String phone);


	/**
	 * 根据邮箱查询用户信息
	 * @param email
	 * @return
	 */
	public SysUser getUserByEmail(@Param("email")String email);

	@Select("select depart_id from sys_user where id =#{userId} and del_flag='0'")
	String selectDepart(String userId);

	@Select("SELECT CONCAT(sd.parent_ids,',',sd.id) as ids FROM base_project bp LEFT JOIN sys_depart sd on sd.id = bp.depart_id  WHERE bp.id = #{projectId}")
    String getDepartIds(String projectId);

	List<SysUser> getUsersByDeparts(@Param("ids") List<String> ids);

    List<SysUser> selectAllRecord(IPage<SysUser> page,@Param("sysUser") SysUser sysUser);

    List<SysUser> selectAllRecordByPosition(IPage<SysUser> page,@Param("sysUser") SysUser sysUser);

	Integer selectUserCount(@Param("userName")String userName);

	List<SysDepart> getUserByDepardId(@Param("depardId") String depardId);
    @Select("SELECT * FROM sys_user where username=#{userName} and del_flag= '0'")
    SysUser getUserByLoginName(@Param("userName") String userName);

	List<SysUser> findAddressBookList(@Param("sysUser") SysUser sysUser);


	List<SysUser> findUserByCompanyId(String companyId);

	List<SysUser> findChildUserByDepartId(String departId);

	void updateBatchById(@Param("list") List<SysUser> sysUserList);

    void autoAccount(@Param("userId") String userId,@Param("loginUserId") String loginUserId);


    //------------------------------server-------------------------------------

    @SqlParser(filter = true)
    List<SysUser> findServerPage(Page<SysUser> page,@Param("bean") SysUser sysUser);
	@SqlParser(filter = true)
    void serverSave(@Param("bean") SysUser sysUser);
	@SqlParser(filter = true)
	int getServerCountByAccount(String adminAccount);
	@SqlParser(filter = true)
    void serverUpdateByName(@Param("bean") SysUser sysUser,@Param("userName") String adminAccount);
}
